package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertFloatToByteArray {
	public static void main(String[] argv) {
		float f = 2.45678f;
		System.out.println(java.util.Arrays.toString(floatToByte(f)));
	}

	public static byte[] floatToByte(float f) {
		return toLH(Float.floatToRawIntBits(f));
	}

	public static byte[] toLH(int n) {
		byte[] b = new byte[4];
		b[0] = (byte) (n & 0xff);
		b[1] = (byte) (n >> 8 & 0xff);
		b[2] = (byte) (n >> 16 & 0xff);
		b[3] = (byte) (n >> 24 & 0xff);
		return b;
	}
}
